<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>BabyOS: b_xpt2046.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="2.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">BabyOS
   &#160;<span id="projectnumber">V1.1.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_b9223522bb56aee4ab59f7ba381d2163.html">bos</a></li><li class="navelem"><a class="el" href="dir_bd0e78931a998067c69a2f2b1c188ef6.html">drivers</a></li><li class="navelem"><a class="el" href="dir_66d2336a6add43b86bead8301b0536f4.html">src</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">b_xpt2046.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="b__xpt2046_8c.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment">/*Includes ----------------------------------------------*/</span></div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="b__xpt2046_8h.html">b_xpt2046.h</a>&quot;</span></div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="b__hal_8h.html">b_hal.h</a>&quot;</span></div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="b__utils_8h.html">b_utils.h</a>&quot;</span></div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#include &lt;string.h&gt;</span></div><div class="line"><a name="l00061"></a><span class="lineno"><a class="line" href="group___x_p_t2046___private___defines.html#ga69b10e1767179197068d54509be8d24a">   61</a></span>&#160;<span class="preprocessor">#define XPT2046_I       0x80</span></div><div class="line"><a name="l00062"></a><span class="lineno"><a class="line" href="group___x_p_t2046___private___defines.html#ga50464f62d694f608197be7b2c62926df">   62</a></span>&#160;<span class="preprocessor">#define XPT2046_X       0xD0</span></div><div class="line"><a name="l00063"></a><span class="lineno"><a class="line" href="group___x_p_t2046___private___defines.html#ga79b991e9cfafa846ebb27f6c00a3f09a">   63</a></span>&#160;<span class="preprocessor">#define XPT2046_Y       0x90   </span></div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="keyword">extern</span> SPI_HandleTypeDef <a class="code" href="group___x_p_t2046___private___variables.html#gaec51920045aad7f70cbfd1f58228d866">hspi3</a>;</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;</div><div class="line"><a name="l00084"></a><span class="lineno"><a class="line" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">   84</a></span>&#160;<a class="code" href="structb_driver_interface__t.html">bXPT2046_Driver_t</a> <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a> = </div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;{</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;        .<a class="code" href="structb_driver_interface__t.html#a857eaefcde68aba9fe0d2170a660fdfb">init</a> = <a class="code" href="group___x_p_t2046___exported___functions.html#ga154a04ec3490a9d74bd6dda386389871">bXPT2046_Init</a>,</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;};</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;<span class="keyword">static</span> uint8_t _bXPT2046TxRx(uint8_t dat)</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;{</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    uint8_t tmp;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    HAL_SPI_TransmitReceive(&amp;<a class="code" href="group___x_p_t2046___private___variables.html#gaec51920045aad7f70cbfd1f58228d866">hspi3</a>, &amp;dat, &amp;tmp, 1, 0xfff);</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    <span class="keywordflow">return</span> tmp;</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;}</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="keyword">static</span> uint16_t _bXPT2046ReadVal(uint8_t r)</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;{</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;    uint16_t l, h;</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;    <a class="code" href="group___h_a_l___exported___defines.html#gab8f742cb77b6722531d6e265043768ee">TP_CS_RESET</a>();</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    _bXPT2046TxRx(r);</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    h = _bXPT2046TxRx(0x00);</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    l = _bXPT2046TxRx(0x00);</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <a class="code" href="group___h_a_l___exported___defines.html#gaba8a54cd6e309557b45081d3fc38b141">TP_CS_SET</a>();</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    <span class="keywordflow">return</span> ((h &lt;&lt; 8) | (l)) &gt;&gt; 3;</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;}</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;</div><div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _bXPT2046Read(uint32_t addr, uint8_t *pbuf, uint16_t len)</div><div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;{</div><div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;    uint16_t *pxy = (uint16_t *)pbuf;</div><div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;    <span class="keywordflow">if</span>(len &lt; 4 || pbuf == <a class="code" href="b__config_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a>)</div><div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;    {</div><div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;        <span class="keywordflow">return</span> -1;</div><div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;    }</div><div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;    pxy[0] = _bXPT2046ReadVal(<a class="code" href="group___x_p_t2046___private___defines.html#ga50464f62d694f608197be7b2c62926df">XPT2046_X</a>);</div><div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;    pxy[1] = _bXPT2046ReadVal(<a class="code" href="group___x_p_t2046___private___defines.html#ga79b991e9cfafa846ebb27f6c00a3f09a">XPT2046_Y</a>);</div><div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;}</div><div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;</div><div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _bXPT2046Close()</div><div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;{</div><div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;    _bXPT2046ReadVal(<a class="code" href="group___x_p_t2046___private___defines.html#ga69b10e1767179197068d54509be8d24a">XPT2046_I</a>);</div><div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;}</div><div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _bXPT2046Open()</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;{</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;}</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _bXPT2046Write(uint32_t addr, uint8_t *pbuf, uint16_t len)</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;{</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;}</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;<span class="keyword">static</span> <span class="keywordtype">int</span> _bXPT2046Ctl(uint8_t cmd, <span class="keywordtype">void</span> * param)</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;{</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;}</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;</div><div class="line"><a name="l00168"></a><span class="lineno"><a class="line" href="group___x_p_t2046___exported___functions.html#ga154a04ec3490a9d74bd6dda386389871">  168</a></span>&#160;<span class="keywordtype">int</span> <a class="code" href="group___x_p_t2046___exported___functions.html#ga154a04ec3490a9d74bd6dda386389871">bXPT2046_Init</a>()</div><div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;{  </div><div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;    _bXPT2046ReadVal(<a class="code" href="group___x_p_t2046___private___defines.html#ga69b10e1767179197068d54509be8d24a">XPT2046_I</a>);</div><div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;    <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a>.<a class="code" href="structb_driver_interface__t.html#a533fda1241149e9fe787957492b2b1fc">close</a> = _bXPT2046Close;</div><div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a>.<a class="code" href="structb_driver_interface__t.html#a671c1e21440d7a8a58f1e244a4880d6f">read</a> = _bXPT2046Read;</div><div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;    <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a>.<a class="code" href="structb_driver_interface__t.html#a92bf484ff16ad77727b6afe688c7e98e">ctl</a> = _bXPT2046Ctl;</div><div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;    <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a>.<a class="code" href="structb_driver_interface__t.html#a87e704566d0a15f1aabbbfb208438c81">open</a> = _bXPT2046Open;</div><div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;    <a class="code" href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a>.<a class="code" href="structb_driver_interface__t.html#af67fbf8f75e899efac0872e7469a33c2">write</a> = _bXPT2046Write;</div><div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;    <span class="keywordflow">return</span> 0;</div><div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;}</div><div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;</div><div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;</div><div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;</div><div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;</div><div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;</div><div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="comment">/************************ Copyright (c) 2019 Bean *****END OF FILE****/</span></div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;</div><div class="ttc" id="b__hal_8h_html"><div class="ttname"><a href="b__hal_8h.html">b_hal.h</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_a533fda1241149e9fe787957492b2b1fc"><div class="ttname"><a href="structb_driver_interface__t.html#a533fda1241149e9fe787957492b2b1fc">bDriverInterface_t::close</a></div><div class="ttdeci">int(* close)(void)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00077">b_device.h:77</a></div></div>
<div class="ttc" id="group___x_p_t2046___private___defines_html_ga79b991e9cfafa846ebb27f6c00a3f09a"><div class="ttname"><a href="group___x_p_t2046___private___defines.html#ga79b991e9cfafa846ebb27f6c00a3f09a">XPT2046_Y</a></div><div class="ttdeci">#define XPT2046_Y</div><div class="ttdef"><b>Definition:</b> <a href="b__xpt2046_8c_source.html#l00063">b_xpt2046.c:63</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_a87e704566d0a15f1aabbbfb208438c81"><div class="ttname"><a href="structb_driver_interface__t.html#a87e704566d0a15f1aabbbfb208438c81">bDriverInterface_t::open</a></div><div class="ttdeci">int(* open)(void)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00076">b_device.h:76</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html"><div class="ttname"><a href="structb_driver_interface__t.html">bDriverInterface_t</a></div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00073">b_device.h:73</a></div></div>
<div class="ttc" id="b__config_8h_html_a070d2ce7b6bb7e5c05602aa8c308d0c4"><div class="ttname"><a href="b__config_8h.html#a070d2ce7b6bb7e5c05602aa8c308d0c4">NULL</a></div><div class="ttdeci">#define NULL</div><div class="ttdef"><b>Definition:</b> <a href="b__config_8h_source.html#l00042">b_config.h:42</a></div></div>
<div class="ttc" id="group___x_p_t2046___private___variables_html_ga2ed61e56408ad8fb94a4240811be42ff"><div class="ttname"><a href="group___x_p_t2046___private___variables.html#ga2ed61e56408ad8fb94a4240811be42ff">bXPT2046_Driver</a></div><div class="ttdeci">bXPT2046_Driver_t bXPT2046_Driver</div><div class="ttdef"><b>Definition:</b> <a href="b__xpt2046_8c_source.html#l00084">b_xpt2046.c:84</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_af67fbf8f75e899efac0872e7469a33c2"><div class="ttname"><a href="structb_driver_interface__t.html#af67fbf8f75e899efac0872e7469a33c2">bDriverInterface_t::write</a></div><div class="ttdeci">int(* write)(uint32_t addr, uint8_t *pbuf, uint16_t len)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00079">b_device.h:79</a></div></div>
<div class="ttc" id="group___h_a_l___exported___defines_html_gab8f742cb77b6722531d6e265043768ee"><div class="ttname"><a href="group___h_a_l___exported___defines.html#gab8f742cb77b6722531d6e265043768ee">TP_CS_RESET</a></div><div class="ttdeci">#define TP_CS_RESET()</div><div class="ttdef"><b>Definition:</b> <a href="b__hal_8h_source.html#l00072">b_hal.h:72</a></div></div>
<div class="ttc" id="group___x_p_t2046___private___defines_html_ga50464f62d694f608197be7b2c62926df"><div class="ttname"><a href="group___x_p_t2046___private___defines.html#ga50464f62d694f608197be7b2c62926df">XPT2046_X</a></div><div class="ttdeci">#define XPT2046_X</div><div class="ttdef"><b>Definition:</b> <a href="b__xpt2046_8c_source.html#l00062">b_xpt2046.c:62</a></div></div>
<div class="ttc" id="b__utils_8h_html"><div class="ttname"><a href="b__utils_8h.html">b_utils.h</a></div></div>
<div class="ttc" id="group___h_a_l___exported___defines_html_gaba8a54cd6e309557b45081d3fc38b141"><div class="ttname"><a href="group___h_a_l___exported___defines.html#gaba8a54cd6e309557b45081d3fc38b141">TP_CS_SET</a></div><div class="ttdeci">#define TP_CS_SET()</div><div class="ttdef"><b>Definition:</b> <a href="b__hal_8h_source.html#l00073">b_hal.h:73</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_a92bf484ff16ad77727b6afe688c7e98e"><div class="ttname"><a href="structb_driver_interface__t.html#a92bf484ff16ad77727b6afe688c7e98e">bDriverInterface_t::ctl</a></div><div class="ttdeci">int(* ctl)(uint8_t cmd, void *param)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00078">b_device.h:78</a></div></div>
<div class="ttc" id="group___x_p_t2046___private___variables_html_gaec51920045aad7f70cbfd1f58228d866"><div class="ttname"><a href="group___x_p_t2046___private___variables.html#gaec51920045aad7f70cbfd1f58228d866">hspi3</a></div><div class="ttdeci">SPI_HandleTypeDef hspi3</div></div>
<div class="ttc" id="b__xpt2046_8h_html"><div class="ttname"><a href="b__xpt2046_8h.html">b_xpt2046.h</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_a671c1e21440d7a8a58f1e244a4880d6f"><div class="ttname"><a href="structb_driver_interface__t.html#a671c1e21440d7a8a58f1e244a4880d6f">bDriverInterface_t::read</a></div><div class="ttdeci">int(* read)(uint32_t addr, uint8_t *pbuf, uint16_t len)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00080">b_device.h:80</a></div></div>
<div class="ttc" id="structb_driver_interface__t_html_a857eaefcde68aba9fe0d2170a660fdfb"><div class="ttname"><a href="structb_driver_interface__t.html#a857eaefcde68aba9fe0d2170a660fdfb">bDriverInterface_t::init</a></div><div class="ttdeci">int(* init)(void)</div><div class="ttdef"><b>Definition:</b> <a href="b__device_8h_source.html#l00075">b_device.h:75</a></div></div>
<div class="ttc" id="group___x_p_t2046___private___defines_html_ga69b10e1767179197068d54509be8d24a"><div class="ttname"><a href="group___x_p_t2046___private___defines.html#ga69b10e1767179197068d54509be8d24a">XPT2046_I</a></div><div class="ttdeci">#define XPT2046_I</div><div class="ttdef"><b>Definition:</b> <a href="b__xpt2046_8c_source.html#l00061">b_xpt2046.c:61</a></div></div>
<div class="ttc" id="group___x_p_t2046___exported___functions_html_ga154a04ec3490a9d74bd6dda386389871"><div class="ttname"><a href="group___x_p_t2046___exported___functions.html#ga154a04ec3490a9d74bd6dda386389871">bXPT2046_Init</a></div><div class="ttdeci">int bXPT2046_Init(void)</div><div class="ttdef"><b>Definition:</b> <a href="b__xpt2046_8c_source.html#l00168">b_xpt2046.c:168</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>
